package crp.services.api.graphql.loaders;

import com.qwlabs.lang.C2;
import crp.services.api.graphql.models.AttachmentPayload;
import crp.services.api.graphql.models.StorageObjectPayload;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Source;

import javax.enterprise.context.RequestScoped;
import javax.validation.constraints.NotNull;
import java.util.List;

@GraphQLApi
@RequestScoped
public class AttachmentPayloadLoader {

    public List<@NotNull List<@NotNull StorageObjectPayload>> items(@Source List<AttachmentPayload> attachments) {
        return C2.list(attachments, attachment -> C2.list(attachment.getItems(), StorageObjectPayload::of));
    }
}
